package cn.miju.ser.wechatpay.controller;


import cn.miju.ser.framework.request.MiJuPayRequest;
import cn.miju.ser.framework.response.MiJuPayResponse;
import cn.miju.ser.wechatpay.serivce.WechatpayService;
import cn.miju.ser.wechatpay.vo.*;
import com.alibaba.fastjson.JSON;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <pre>
 *
 * 文件名 :  WechatController
 * 创建时间 : 2023年03月16日 11:04
 * 文件描述 : 无
 *
 * </pre>
 *
 * @author Huzb
 * @version 1.0.0
 */
@RestController
@RequestMapping("/wechatpay")
@RequiredArgsConstructor
public class WechatpayController {

    private final WechatpayService wechatpayService;

    /**
     * 扫码支付下单
     *
     * @param miJuPayRequest 入参
     * @return 反参
     */
    @PostMapping("/createQrcodeOrder")
    public MiJuPayResponse createQrcodeOrder(@RequestBody @Validated MiJuPayRequest miJuPayRequest) {
        CreateQrcodeOrderOutVO outVO = wechatpayService.createQrcodeOrder(JSON.parseObject(miJuPayRequest.getBizContent(), CreateQrcodeOrderInVO.class));
        return MiJuPayResponse.success(JSON.toJSONString(outVO));
    }


    /**
     * 查询订单
     *
     * @param miJuPayRequest 入参
     * @return 反参
     */
    @PostMapping("/queryOrder")
    public MiJuPayResponse queryOrder(@RequestBody @Validated MiJuPayRequest miJuPayRequest) {
        QueryOrderOutVO outVO = wechatpayService.queryOrder(JSON.parseObject(miJuPayRequest.getBizContent(), QueryOrderInVO.class));
        return MiJuPayResponse.success(JSON.toJSONString(outVO));
    }


    /**
     * 订单关闭
     *
     * @param miJuPayRequest 入参
     * @return 反参
     */
    @PostMapping("/closeOrder")
    public MiJuPayResponse closeOrder(@RequestBody @Validated MiJuPayRequest miJuPayRequest) {
        CloseOrderOutVO outVO = wechatpayService.closeOrder(JSON.parseObject(miJuPayRequest.getBizContent(), CloseOrderInVO.class));
        return MiJuPayResponse.success(JSON.toJSONString(outVO));
    }


    /**
     * 订单退款
     *
     * @param miJuPayRequest 入参
     * @return 反参
     */
    @PostMapping("/refundOrder")
    public MiJuPayResponse refundOrder(@RequestBody @Validated MiJuPayRequest miJuPayRequest) {
        RefundOrderOutVO outVO = wechatpayService.refundOrder(JSON.parseObject(miJuPayRequest.getBizContent(), RefundOrderInVO.class));
        return MiJuPayResponse.success(JSON.toJSONString(outVO));
    }
}
